package com.bkhc.product.api;

import com.bkhc.common.annotation.ApiOperation;
import com.bkhc.common.annotation.ApiPackage;
import com.bkhc.common.annotation.AuditLog;
import com.bkhc.common.enu.OperationEnum;
import com.bkhc.common.util.response.ResultJson;
import com.bkhc.product.entity.Product;
import com.bkhc.product.service.ProductService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api("产品管理服务")
@RequestMapping("/")
@ApiPackage(code="product-api",name="产品管理服务",description = "后台产品管理维护操作接口")
public class ProductController extends CommonController {

    @Autowired
    private ProductService productService;

    @ApiOperation(code="findProduct",name="查询产品",description = "查询产品",type = "common")
    @AuditLog(object="Product",operation = "查询产品",type = OperationEnum.query)
    @RequestMapping(path = "list/{pageNum}/{pageSize}",method = RequestMethod.POST)
    public ResultJson<?> findProduct(@RequestBody(required=false) Product product, @PathVariable(name="pageNum") int pageIndex, @PathVariable(name="pageSize") int pageSize) {
        ResultJson<?> res = productService.findProduct(product, pageIndex, pageSize);
        return res;
    }

    @ApiOperation(code="findProductByUserId",name="查询当前用户的产品",description = "查询当前用户的产品",type = "common")
    @AuditLog(object="Product",operation = "查询当前用户的产品",type = OperationEnum.query)
    @RequestMapping(path = "list/userId/{pageNum}/{pageSize}",method = RequestMethod.POST)
    public ResultJson<?> findProductByUserId(@PathVariable(name="pageNum") int pageIndex, @PathVariable(name="pageSize") int pageSize) {
        ResultJson<?> res = productService.findProductByUserId(pageIndex, pageSize);
        return res;
    }

    @ApiOperation(code="detail",name="查询产品详情",description = "查询产品详情",type = "common")
    @AuditLog(object="Product",operation = "查询产品详情",type = OperationEnum.query)
    @RequestMapping(path = "detail/{productCode}",method = RequestMethod.POST)
    public ResultJson<?> findProductDetail(@PathVariable(name="productCode")String productCode) {
        ResultJson<?> res = productService.findProductDetail(productCode);
        return res;
    }


    @ApiOperation(code="addProduct",name="增加产品",description = "增加产品")
    @AuditLog(object="Product",operation = "增加产品",type = OperationEnum.query)
    @RequestMapping(path = "add",method = RequestMethod.POST)
    public ResultJson<?> addProduct(@RequestBody(required=false) Product product) {
        ResultJson<?> res = productService.addProduct(product);
        return res;
    }

    @ApiOperation(code="addProductSchema",name="产品建档",description = "产品建档")
    @AuditLog(object="Product",operation = "产品建档",type = OperationEnum.query)
    @RequestMapping(path = "addProductSchema",method = RequestMethod.POST)
    public ResultJson<?> addProductSchema(@RequestBody(required=false) Product product) {
        ResultJson<?> res = productService.addOrUpdateProductSchema(product);
        return res;
    }

    @ApiOperation(code="addProductStandard",name="产品技术规范",description = "产品技术规范")
    @AuditLog(object="Product",operation = "产品技术规范",type = OperationEnum.query)
    @RequestMapping(path = "addProductStandard",method = RequestMethod.POST)
    public ResultJson<?> addProductStandard(@RequestBody(required=false) Product product) {
        ResultJson<?> res = productService.addProductStandard(product);
        return res;
    }

    @ApiOperation(code="queryProductFiles",name="查询技术文档",description = "查询技术文档")
    @AuditLog(object="Product",operation = "查询技术文档",type = OperationEnum.query)
    @RequestMapping(path = "queryProductFiles/{productCode}",method = RequestMethod.POST)
    public ResultJson<?> queryProductFiles(@PathVariable(name="productCode")String productCode) {
        ResultJson<?> res = productService.queryProductFiles(productCode);
        return res;
    }

    @ApiOperation(code="queryProductVideo",name="查询技术视频",description = "查询技术视频")
    @AuditLog(object="Product",operation = "查询技术视频",type = OperationEnum.query)
    @RequestMapping(path = "queryProductVideo/{productCode}",method = RequestMethod.POST)
    public ResultJson<?> queryProductVideo(@PathVariable(name="productCode")String productCode) {
        ResultJson<?> res = productService.queryProductVideo(productCode);
        return res;
    }

    @ApiOperation(code="findAllProducts",name="查询所有产品",description = "查询所有产品")
    @AuditLog(object="Product",operation = "查询所有产品",type = OperationEnum.query)
    @RequestMapping(path = "all",method = RequestMethod.POST)
    public ResultJson<?> findAllProducts() {
        ResultJson<?> res = productService.findAllProducts();
        return res;
    }

    @ApiOperation(code="updatePartnerId",name="更新合伙人id",description = "更新合伙人id")
    @AuditLog(object="Product",operation = "更新合伙人id",type = OperationEnum.query)
    @RequestMapping(path = "update/{id}/{partnerId}",method = RequestMethod.POST)
    public ResultJson<?> updatePartnerId(@PathVariable Integer id, @PathVariable String partnerId) {
        ResultJson<?> res = productService.updatePartnerId(id, partnerId);
        return res;
    }

    @ApiOperation(code="updateProduct",name="修改产品",description = "修改产品")
    @AuditLog(object="Product",operation = "修改产品",type = OperationEnum.update)
    @RequestMapping(path = "product/update",method = RequestMethod.POST)
    public ResultJson<?> updateProduct(@RequestBody(required=false) Product product) {
        ResultJson<?> res = productService.updateProduct(product);
        return res;
    }

    @ApiOperation(code="deleteProduct",name="删除产品",description = "删除产品")
    @AuditLog(object="Product",operation = "删除产品",type = OperationEnum.delete)
    @RequestMapping(path = "delete/{productCode}",method = RequestMethod.POST)
    public ResultJson<?> deleteProduct(@PathVariable(name="productCode") String productCode) {
        ResultJson<?> res = productService.deleteProduct(productCode);
        return res;
    }

    @ApiOperation(code="querySpecByProductCode",name="查询单个产品规格",description = "查询单个产品规格",type = "common")
    @AuditLog(object="Product",operation = "查询单个产品规格",type = OperationEnum.query)
    @RequestMapping(path = "querySpecByProductCode",method = RequestMethod.POST)
    public ResultJson<?> querySpecByProductCode(@RequestParam(name="productCode") String productCode) {
        ResultJson<?> res = productService.querySpecByProductCode(productCode);
        return res;
    }

}
